package com.example.fengyungo.controller.user.driver;

import com.example.fengyungo.constant.MsgConstant;
import com.example.fengyungo.domain.pojo.Driver;
import com.example.fengyungo.domain.pojo.User;
import com.example.fengyungo.result.Result;
import com.example.fengyungo.service.DriverService;
import com.example.fengyungo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

@RestController
@RequestMapping("/user/driver")
public class DriverUserController {

    @Autowired
    private UserService userService;

    /**
     * 根据id获取用户信息
     *
     * @param id String
     * @return Result
     */
    @GetMapping("/getUserById/{id}")
    @Cacheable(value = "user", key = "'getUserById'+#id")
    public Result<User> getUserById(@PathVariable String id) {
        User user = userService.getUserById(id);
        if (user != null) {
            return Result.success(user);
        } else {
            return Result.error(MsgConstant.USER_INFO_NOT_EXISTS);
        }
    }
}
